<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>找回密码</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/login.css">
    <link rel="stylesheet" href="css/myinfo.css">
    <script src="js/common.js"></script>
    <script src="js/jquery.min.js"></script>

</head>


<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/default.jpg" alt="">
        <a class="title" href="blog_list.html">博客系统</a>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="login.html">登录</a>
        <a href="reg.html">注册</a>
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <div class="login-dialog" style="height: 490px;">
            <h3>找回密码</h3>
            <!-- 账号模块 -->
            <div id="ps" style="width: 326px; margin: 8px 90px;">Ps：为保护帐号安全，找回密码需要进行资料辅助验证。只有当你提供的资料足够真实完整，才能通过验证。</div>
            <div class="row">
                <span>找回账号</span>
                <input type="text" id="username">
            </div>

            <hr>

            <div class="row">
                <span id="ps" style="width: 325px;">Ps：以下为密保信息，若该账号没有设置密保信息，则会将当前输入信息作为密保进行设置</span>
            </div>
            <div class="row">
                <span>真实姓名</span>
                <input type="text" id="realname">
            </div>
            <div class="row">
                <span>身份证号</span>
                <input type="text" id="idcard">
            </div>

            <hr>

            <div class="row">
                <span id="ps">Ps：输入完密保信息后，请设置新密码</span>
            </div>
            <div class="row">
                <span>新密码</span>
                <input type="text" id="password1">
            </div>
            <div class="row">
                <span>确认密码</span>
                <input type="text" id="password2">
            </div>
            <div class="row">
                <button id="submit" onclick="subInfo()" style="margin-top: 15px;">提交</button>
            </div>
        </div>
    </div>

    <script>

        //提交用户信息
        function subInfo() {
            //非空校验
            var username = jQuery("#username");
            if (username.val() == "") {
                alert("账号不能为空!");
                username.focus();
                return;
            }
            var realname = jQuery("#realname");
            if (realname.val() == "") {
                alert("真实姓名不能为空!");
                realname.focus();
                return;
            }
            var idcard = jQuery("#idcard");
            if (idcard.val() == "") {
                alert("身份证号不能为空!");
                idcard.focus();
                return;
            }
            var password1 = jQuery("#password1");
            if (password1.val() == "") {
                alert("新密码不能为空!");
                password1.focus();
                return;
            }
            var password2 = jQuery("#password2");
            if (password2.val() == "") {
                alert("确认密码不能为空!");
                password2.focus();
                return;
            }
            //校验密码
            if (password1.val() != password2.val()) {
                alert("两次输入密码不一致，请重试!");
                password1.focus();
                return;
            }
            jQuery.ajax({
                type: "POST",
                url: "/user/check-security",
                data: {
                    "username": username.val(),
                    "realname": realname.val(),
                    "idcard": idcard.val(),
                    "password": password1.val()
                },
                success(result) {
                    if(result != null && result.code == 200 && result.data == 1) {
                        if(confirm("找回密码成功，新密码已为您绑定!是否跳转到登录页面?")) {
                            location.assign("login.html");
                        }
                    } else {
                        alert(result.msg);
                    }
                }
            });

        }

    </script>

</body>

</html>